﻿using System;

namespace StevensReceipts.Repository
{
    public class OperationStatus
    {
        public bool Status { get; set; }
        public string Message { get; set; }
        public int RecordsAffected { get; set; }
        public Object OperationId { get; set; }
        public string ExceptionMessage { get; set; }
        public string ExceptionStackTrack { get; set; }
        public string ExceptionInnerMessage { get; set; }
        public string ExceptionInnerStackTrack { get; set; }


        public static OperationStatus CreateFromException(string message, Exception exception)
        {
            var opstatus = new OperationStatus
                                           {
                                               Status = false,
                                               Message = message,
                                               OperationId = null
                                           };
            if(exception != null)
            {
                opstatus.ExceptionMessage = exception.Message;
                opstatus.ExceptionInnerMessage = exception.InnerException == null? string.Empty : exception.InnerException.Message;
                opstatus.ExceptionStackTrack = exception.StackTrace;
                opstatus.ExceptionInnerStackTrack = exception.InnerException == null ? string.Empty: exception.InnerException.StackTrace;
            }
            return opstatus;
        }
    }
}
